﻿using System;
using System.Collections.Generic;
using System.Text;
using Tools;

namespace MtwControl
{
    public class KeyObject
    {
        /// <summary>
        /// 键盘虚拟码
        /// </summary>
        private byte keycode;
        /// <summary>
        /// 键按下还是弹起的操作
        /// </summary>
        private uint keyaction;
        private static Log log;
        private Ps2 ps2;
        public KeyObject()
        {
            log = new Log(this);
            ps2 = new Ps2();
           
        }
        public void excute(String msg)
        {
            log.debug(msg);
            keycode = Convert.ToByte(msg.Split('-')[0].Trim());
            //判断键盘动作是按下还是弹起，消息结构请参考MTW的MOBLIE端，
            keyaction = msg.Split('_')[1].Equals("DOWN") ? (uint)0 : (uint)2;
            if (keyaction == 0)
            {
                //down
                ps2.keyDown(keycode);
            }
            else
            {
                //up
                ps2.keyUp(keycode);
            }

            //ExternFun.keybd_event(keycode, keycode, keyaction, 0);
        }
    }
}
